/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.cip.esymons.tramite.converters;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.ConverterException;
import org.cip.esymons.tramite.be.EnumTipoTramite;

/**
 *
 * @author ChristianATE
 */
public class EnumTipoTramiteConverter implements Converter {

    public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2)throws ConverterException {
        if(arg2 == null || (arg2.equals("Seleccionar"))){
            return null;
        }
        try{
            return EnumTipoTramite.valueOf(arg2);
        }catch(Exception ex){
            return null;
        }
    }

    public String getAsString(FacesContext arg0, UIComponent arg1, Object arg2)throws ConverterException {
        if(arg2 == null){
            return null;
        }
        if(arg2 instanceof EnumTipoTramite){
            return ((EnumTipoTramite)arg2).name();
        }else{
            return null;
        }
    }
}